<?php

namespace app\admin\controller;

use think\Request;
use think\Db;
use think\Controller;
use think\Loader;

class Password extends Common {

    public function index(){
        return $this->fetch();
    }
    public function dopassword(){
        if ($_POST['oldpass']) {
            $oldpass = input('post.oldpass');
            $newpass = input('post.newpass');
            $repass = input('post.repass');
            $username = session('username');
            $result = Db::table('ticket_user')->where('name',$username)->find();
            if(md5(md5($oldpass)) != $result['password']){
                $this->error('密码输入错误');
            }
            if($repass != $oldpass){
                $this->error('请确认您的密码');
            }
            $newpass = md5(md5($newpass));
            Db::table('ticket_user')->where('name',$username)->update(['password'=>$newpass]);
            cookie('username', null);
            cookie('token', null);
            //session(null);
            session_destroy();
            $this->success('密码修改成功', 'admin/login/index');
        }
        else{
            $this->error('请输入密码');
        }
    }

    public function test(){
        echo "test";
    }

}